package com.financing.platform.web.api;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;
import com.financing.platform.service.IFpFundCMService;
import com.financing.platform.common.Pager;
import com.financing.platform.common.ResultCode;
import com.financing.platform.common.ResultMap;
import com.financing.platform.common.ResultMap.STATUS;
import com.financing.platform.util.DTOdateSet;
import com.financing.platform.dto.FpFundCMDTO;

/**
 * @Description: Controller
 * @author caojiayao
 * @version 1.0
 * @created 
 */
@Controller
@RequestMapping("/api/fund")
@Scope("prototype")
public class FpFundCMAction  extends BaseAction {
	@Autowired
	private IFpFundCMService fpFundCMService;
	
	@RequestMapping("/fpFundCMQueryList.shtml")
	@ResponseBody
	public ResultMap queryList(HttpServletRequest request,
			HttpServletResponse response,FpFundCMDTO dto,Pager pager) {
		try{
			log.info("Begin query fa user list!");
			
			dto.setBegin(pager.getStartIndex());
			dto.setPageSize(pager.getPageSize());
			
			int count = fpFundCMService.countFpFundCM(dto);
			pager.setTotalCount(count);
			List<FpFundCMDTO> list = fpFundCMService.listFpFundCMByPage(dto);
			
			resultMap.setAttribute("list",list);
			resultMap.setAttribute("pager", pager);
			resultMap.setStatus(STATUS.SUCCESS);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			
			log.info("End querylist!");
		}catch(Exception e){
			log.error("queryList error !",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			
			return resultMap;
	}
	
	@RequestMapping("/fpFundCMDelete.shtml")
	@ResponseBody
	public ResultMap delete(HttpServletRequest request,
			HttpServletResponse response,FpFundCMDTO dto) {
		try{
			log.info("Begin delete fa user info !");
			int count = fpFundCMService.delFpFundCM(dto.getId());
			
			resultMap.getAttribute().put("delete count",count);
			
			if(count > 0){
			    resultMap.setStatus(STATUS.SUCCESS);
				resultMap.setStatusCode(ResultCode.RESULT_CODE_SUCCESS);
			}else{
				resultMap.setStatus(STATUS.FAILE);
				resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
			}
			log.info("End delete fa user info !");
		}catch(Exception e){
			log.error("delete fa user info error!",e);
			resultMap.setStatus(STATUS.FAILE);
			resultMap.setStatusCode(ResultCode.RESULT_CODE_SYSTEM_ERROR);
		}
			
			return resultMap;
				
	}
}